package com.ly.hotel.spainterface.jg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.spainterface.jg.bean.Massage;

import java.util.List;

/**
 * Created by ThinkPad on 2018/3/15.
 */

public class MassageHideAdapter extends BaseAdapter {

    private Context context;
    private List<Massage> massageList;
    private int defaultItem = 0;

    public MassageHideAdapter(Context context, List<Massage> massageList){
        this.context = context;
        this.massageList = massageList;
    }

    // 设置选中项
    public void setDefaultItem(int position){
        this.defaultItem = position;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return massageList.size();
    }

    @Override
    public Object getItem(int position) {
        return massageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.jg_listview_massage_item,null);
            viewHolder = new ViewHolder();
            viewHolder.massageItemName = view.findViewById(R.id.massage_item_name);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        // 设置字体默认颜色
        viewHolder.massageItemName.setTextColor(context.getResources().getColor(R.color.moreGray));
        if(defaultItem == position){ // defaultItem值为0的时候，只是界面上选中了第一项，实质上并没有调用点击事件；
            view.setBackgroundResource(R.color.itemSelect);
            viewHolder.massageItemName.setTextColor(context.getResources().getColor(R.color.newRed));
        }else{
            view.setBackgroundResource(android.R.color.transparent);
        }
        Massage massage = massageList.get(position);
        viewHolder.massageItemName.setText(massage.getName());
        return view;
    }

    class ViewHolder{
        TextView massageItemName;
    }
}
